package com.song.druid.util;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

public class JSONUtils {
    public static <T> T readJsonObject(String filePath, Class<T> t){
        try {
            String jsonStr = new String(Files.readAllBytes(Paths.get(filePath)));
            return JSONObject.parseObject(jsonStr, t);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static <T> List<T> readJsonArray(String filePath, Class<T> t){
        try {
            String jsonStr = new String(Files.readAllBytes(Paths.get(filePath)));
            return JSONObject.parseArray(jsonStr, t);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
